package com.dg11185.nearshop.net;

import com.dg11185.libs.network.http.client.HttpRequest;
import com.dg11185.libs.utils.file.FileUtils;
import com.dg11185.nearshop.app.MyApplication;

public class CacheConstant {

    public static final long CACHE_ONE_HOUR = 3600000; // 一小时
    
    public static final long CACHE_ONE_DAY = 86400000;  //一天

    public static String getCachePath() {
        StringBuilder builder = new StringBuilder();
        if (FileUtils.hasSDCard()) {
            builder.append(FileUtils.getSDCardRootPath()).append("/Android/data/")
                    .append(MyApplication.getContext().getPackageName()).append("/cache/");
        } else {
            builder.append(MyApplication.getContext().getCacheDir()).append("/");
        }
        return builder.toString();
    }

    /**删除缓存文件*/
    public static void deleteCacheFile(@SuppressWarnings("rawtypes") HttpRequest request) {
        if(request == null || request.getParams().size()==0){
            return;
        }
        if(request.getParams().get("chshSign") == null){
            return;
        }else{
            String fileName = (String) request.getParams().get("chshSign");
            FileUtils.deleteFile(getCachePath() + fileName.hashCode());
        }
    }
    
    /**接口包含可选参数时，调用该方法删除一个接口的所有缓存文件*/
    public static void deleteCacheFolder(String folderName){
        FileUtils.deleteDirectory(getCachePath()+ folderName);
    }
}
